<?php

	require_once( '../system/smarty.inc' );
	require_once( '../system/tdao/Class_T_MON_CELL.php' );
	require_once( '../system/tdao/Class_T_MON_CELL_WEEK.php' );
	require_once( '../system/tdao/Class_T_PATTERN.php' );
	require_once( '../system/mdao/Class_M_OTHER.php' );
	require_once( '../system/Class_ERROR.php' );
	require_once( '../system/Class_PWD.php' );
	require_once( '../system/login.inc.php' );
	require_once( '../system/aoki_m_plus.php' );
	
	Class_PWD::valid_auth(AOKI_AUTH_MON_CELL, $login['staff_auth']);
	
	$dao     = new Class_T_MON_CELL_WEEK;
	$dao_mg  = new Class_T_MON_CELL;
	
	$errmsg     = "";
	$datas      = array();
	$phase      = 'input';
	$aja_exits  = true;
	$can_edit   = false;
	
	$fwidth =array("title" =>230, "size"=> 33,"sample" => 80, "num" => 80,"pattern" => 120   );
	$fwidth["cw"] = $fwidth["title"] + $fwidth["size"]   + $fwidth["sample"] + $fwidth["num"]     +  $fwidth["pattern"]+  $fwidth["sample"]+  $fwidth["num"]+  $fwidth["pattern"] +8 ;
	$fwidth["ww"] = $fwidth["size"]  + $fwidth["sample"] + $fwidth["num"]    + $fwidth["pattern"] + 4;
	$fwidth["lw"] = $fwidth["title"] + $fwidth["size"]   + $fwidth["num"]    + $fwidth["pattern"] +  $fwidth["num"]+  $fwidth["pattern"] +6 ;

	$params = array();
	if( $_SERVER['REQUEST_METHOD'] == 'GET' ){
		if( isset($_GET['ww']) && $_GET['ww'] != '' && $_GET["sort"] ){
			$matrix_cd   = $_GET['ww'];
			$dao_mg->setTableNameWeek($matrix_cd);
			if ($_GET["sort"] == '2') {
				if  ( empty( $_GET['areauser'] ) ) {
					$edit_msg = "AJAREKSコードは入力必須です";
					$aja_exits = false;
				}else {
					$aja_cd = $_GET['areauser'];
					$params['area_aja'] = $aja_cd;
				}
			}
			
			if ($_GET["sort"] == '3') {
				$zone_cd = $_GET['zone_cd'];
				$zone_cd = trim($zone_cd);
				if  ( empty($zone_cd) ) {
					$edit_msg = "AJAREKSコードは入力必須です";
					$aja_exits = false;
				}else {
					$aja_cd = $zone_cd;
					$params['zone_aja'] = $zone_cd;
				}
			}
		}
	}else {
		$matrix_cd       = $_POST["matrix_cd"];
		$aja_cd          = $_POST["aja_cd"];

	}
	if ( $login['staff_auth'] == 'G-2'  ) {
		$aja_cd   = $login['autoid'];
		$params['area_aja'] = $aja_cd;
		$smarty->assign('isG23', $isG23 );
	}
	
	if (  $login['staff_auth'] == 'G-3' ) {
		$aja_cd   = $login['autoid'];
		$params['zone_aja'] = $aja_cd;
		$smarty->assign('isG23', $isG23 );
	}
	if ( empty($matrix_cd) ) {
		//$forms['auth'] = 0;
		$edit_msg = "マトリクスコードは入力必須です";
	}
	if ( empty($aja_cd) ) {
		//
		$edit_msg = "AJAREKSコードは入力必須です";
		$aja_exits = false;
	}
//-------権限チェック------------------------------------

	$formdata["matrix_cd"] = $matrix_cd;
	$formdata["aja_cd"]    = $aja_cd;
	//$formdata["sort"]      = $aja_cd;
	$data_mg = $dao_mg->getMatrixTerm( $matrix_cd);
	
	$formdata["year4"]      = $data_mg["year4"];
	$formdata["week_seq"]   = $data_mg["week_seq"];
	$formdata["week_cd"]    = $data_mg["week_cd"];
	$formdata["flier_date"] = Class_PWD::int8_to_dateD( $data_mg["flier_date"] );
	$statusID               = Class_PWD::getMatrixStatues( $data_mg );
	
	$formdata["status"]     = $aoki_matrix_status[$statusID]; 
	$formdata["u_time"]     = $data_mg["upd_time"];		
	$is_final = FALSE;
	//前年データを抽出する
	$pre_matrix_cd = $formdata["pre_matrix_cd"];
	
	if ($aja_exits) {
		
		$login_auth = $login['staff_auth'];
		
		//if ( $login_auth == 'G-2' ) {
		//	$aja_cd          = $login['autoid'];
		//}
		$can_edit = FALSE;
		$edit_msg = "編集できません";

		if (($login_auth == 'G-0') || ( $login_auth== 'G-1') ||  ($login_auth == 'G-2') ||  ($login_auth == 'G-3')) {
			switch ( $statusID ) {
				case AOKI_MATRIXS_DRAFT_CREATE:
				case AOKI_MATRIXS_DRAFT_MODIFY:
				case AOKI_MATRIXS_FINAL_MODIFT:
					if ( $login_auth == 'G-1' ) {
						$edit_msg = "";
						$can_edit = TRUE;
					}
					break;
					
				case AOKI_MATRIXS_DRAFT_INPUT:
				case AOKI_MATRIXS_FINAL_INPUT:
					if ( ( $login_auth == 'G-2' )|| ( $login_auth == 'G-3' )  ) {
						$edit_msg = "";
						$can_edit = TRUE;
					}
					break;
					
				case AOKI_MATRIXS_FINAL_END:
					if ( $login_auth == 'G-1' ) {
						$edit_msg = "FINAL手配済みのデータです";						
						$can_edit = TRUE; 			
					}
					break;
				
				default:
					$edit_msg = "編集期限外です(ステータス：".$aoki_matrix_status[$statusID].") " ;
					break;
			}
			
			switch ( $statusID ) {
				case AOKI_MATRIXS_FINAL_INPUT:
				case AOKI_MATRIXS_FINAL_MODIFT:
				case AOKI_MATRIXS_FINAL_END:
					$is_final = TRUE;
					break;
			}
		}else {
			$edit_msg = "編集権限がありません";
		}
		
		//if ( $login_auth == 'G-0' ) {
			
			$edit_msg = "";
			$can_edit = TRUE;
		//}
	}
	//-------権限チェック---------------end---------------------
	//$is_final = FALSE;]
	if ($can_edit && $aja_exits) {
	//-------------------各パラメタ―作成-------------------------------------------------------------
		$data_title     = $dao_mg->getTitle( $matrix_cd );
	
	require_once( '../system/cell_parametas.inc.php' );
	//-------------各パラメタ―作成完了---------------------------------------------------------------
	if( $_SERVER['REQUEST_METHOD'] == 'GET' ){
		//一覧のデータを抽出する
		$datas = $dao_mg->getMapGroupShop( $matrix_cd , $params );
		//レギュラー   イレギュラー  地域1-5整形
		$shopmapno  = array();
		$subshoparr = array();
		foreach  ( $datas as $k => $v) {
			$shopmapno[$k]  = array("r"=>$v["r"], "i"=>$v["i"],"m4"=>$v["m4"],"m5"=>$v["m5"],"l1"=>$v["l1"],"l2"=>$v["l2"],"l3"=>$v["l3"],"l4"=>$v["l4"],"l5"=>$v["l5"] );
			//$subshoparr[$k] =  array("group_no" =>$v["group_no"] ,"mark" =>$v["mark"]);
			//$datas[$k]["rgyu"]   = "";
			//$datas[$k]["irgyu"]  = "";
			//$datas[$k]["lnews1"] = "";
			//$datas[$k]["lnews2"] = "";
			//$datas[$k]["lnews3"] = "";
			//$datas[$k]["lnews4"] = "";
			//$datas[$k]["lnews5"] = "";
			$datas[$k]["sale"]   = $aoki_shop_sale[$v["sale"]];
			$datas[$k]["plane_cost"]   = $v["plane_cost"] ? $v["plane_cost"] : 0 ;
			$datas[$k]["plane_qua"]    = $v["plane_qua"] ? $v["plane_qua"] : 0 ;
			$datas[$k]["ratio"]   =  $v["mark"] == '0' ? 1 : $v["ratio"] /100.0;
			
		}
		$_SESSION['SHOPMAPNO'] = $shopmapno;
	
		$details = $dao_mg->getCellDetails( $matrix_cd, $is_final, $aja_cd );
	
		$pattern_size_prices = $dao_mg->getAreaPatternPrice( $formdata["year4"] );

		foreach ( $details as $k => $v) {
			$bSize   = strtolower( $v["size"] );
			$bUpperSize = strtoupper( $v["size"] );
			$shop_cd = $v["shop_cd"];
			$wtype   = $v["wtype"];//9  非例外曜日　0-6 例外曜日の番号　
			$qtype   = $v["qtype"];//0  通常チラシ　1 地域１、2 地域2、3 地域3、4 地域4、5 地域5]
			if ( $qtype == "0" ) {
					$mymap   = "mp" ;

					$mymapno = "mpno" ;
					$mytpye  = "tp" ;
					$mymemo  = "mo" ;
					$mytitle = "title_cd" ;
					$datas[$shop_cd][$mytitle] = $v["title_cd"];
					$datas[$shop_cd][$mymapno]  = $v["map_no"];
					$datas[$shop_cd]["isirgyu"] = $v["isirgyu"];
					
				if ( $wtype == "9" ) {
					$maparr  = $data_title_map_arr[ $v["title_cd"] ] ;
					$datas[$shop_cd][$mymap]    = $aoki_map_sort[$v["isirgyu"]];
					
					$datas[$shop_cd][$mytpye]   = $maparr["type"];
					$datas[$shop_cd][$mymemo]   = $maparr["memo"];
					
					$mypc    = "pc_".$bSize;
					$mynpc   = "npc_".$bSize;
					$mysmpc  = "smpc_".$bSize;
					
					$datas[$shop_cd][$mypc]    = $v["pattern_cd"];
					$datas[$shop_cd][$mynpc]   = $v["pnums"];
					$datas[$shop_cd][$mysmpc]  = $v["sample"];
					
				} else {
					$mytitle = $data_cell_wsets[$wtype]["title_cd"] ;
					$maparr  = $data_title_map_arr[ $v["title_cd"] ] ;
					/*
					$mymap   = $data_cell_wsets[$wtype]["mp"] ;
					$mymapno = $data_cell_wsets[$wtype]["mpno"] ;
					$mytpye  = $data_cell_wsets[$wtype]["tp"] ;
					$mymemo  = $data_cell_wsets[$wtype]["mo"] ;
					*/
					$mypc    = $data_cell_wsets[$wtype]["pc_".$bSize];
					$mynpc   = $data_cell_wsets[$wtype]["npc_".$bSize];
					$mysmpc  = $data_cell_wsets[$wtype]["smpc_".$bSize];
					
					$datas[$shop_cd][$mytitle] = $v["title_cd"];
					
					$datas[$shop_cd][$mymap]    = $aoki_map_sort[$v["isirgyu"]];
					$datas[$shop_cd][$mymapno]  = $v["map_no"];
					$datas[$shop_cd][$mytpye]   = $maparr["type"];
					$datas[$shop_cd][$mymemo]   = $maparr["memo"];
					
					$datas[$shop_cd][$mypc]    = $v["pattern_cd"];
					$datas[$shop_cd][$mynpc]   = $v["pnums"];
					$datas[$shop_cd][$mysmpc]  = $v["sample"];	

								
				}
				/*
				if ( $maparr) {
					if ($maparr[0] == 2) {
						$datas[$shop_cd]["irgyu"]  = $shopmapno[$shop_cd]["i"];
						$datas[$shop_cd]["hirgyu"] =  $shopmapno[$shop_cd]["i"];
					} elseif ($maparr[0] == 3) {
						$datas[$shop_cd]["irgyu"]  = $maparr[1];
						$datas[$shop_cd]["hirgyu"] =  $shopmapno[$shop_cd]["i"];
					} else {
						$datas[$shop_cd]["rgyu"] = $shopmapno[$shop_cd]["r"];
					}
				}
				*/
			}else {
				if ( $wtype == "9" ) {
					$maparr = $data_title_map_local_arr[ $v["title_cd"] ] ;
					
					$mytitle = $data_cell_losets[$qtype]["title_cd"] ;
					$mymap   = $data_cell_losets[$qtype]["mp"] ;
					$mymapno = $data_cell_losets[$qtype]["mpno"] ;
					$mytpye  = $data_cell_losets[$qtype]["tp"] ;
					$mymemo  = $data_cell_losets[$qtype]["mo"] ;
					$myisirgyu  = $data_cell_losets[$qtype]["isirgyu"] ;
					
					
					$mypc    = $data_cell_losets[$qtype]["pc_".$bSize];
					$mynpc   = $data_cell_losets[$qtype]["npc_".$bSize];
					$mysmpc  = $data_cell_losets[$qtype]["smpc_".$bSize];
					
					$datas[$shop_cd][$mytitle] = $maparr["title"];
					
					$datas[$shop_cd][$mymap]   = $aoki_map_sort[$v["isirgyu"]];
					
					$datas[$shop_cd][$mymapno] = $v["map_no"];
					$datas[$shop_cd][$mytpye]  = $maparr["tp"];
					$datas[$shop_cd][$mymemo]  = $maparr["mo"];
					
					$datas[$shop_cd][$mypc]    = $v["pattern_cd"];
					$datas[$shop_cd][$mynpc]   = $v["pnums"];
					$datas[$shop_cd][$mysmpc]  = $v["sample"];
					$datas[$shop_cd][ "lnews".$qtype  ] =  $shopmapno[$shop_cd][ "l".$qtype ];
					if (!empty($v["pattern_cd"])  ){
						$num = ( empty($v["pnums"])?0:$v["pnums"] );
						if (isset($pattern_size_prices[$v["pattern_cd"]][$bUpperSize] ) ){
							$loc_cost = $num * $pattern_size_prices[$v["pattern_cd"]][$bUpperSize];
							//echo "**{$shop_cd}**{$loc_cost}**$num**<br>";
							 $datas[$shop_cd]["loc_cost"] = empty($datas[$shop_cd]["loc_cost"]) ? $loc_cost : $datas[$shop_cd]["loc_cost"] + $loc_cost;
						} 
							
					}
					
				} else {
					/*
					$dweeksets = $data_cell_losets[$qtype]["weeks"] ;
					
					$mytitle = $dweeksets[$wtype]["title_cd"] ;
					$mypc    = $dweeksets[$wtype]["pc_".$bSize];
					$mynpc   = $dweeksets[$wtype]["npc_".$bSize];
					
					$datas[$shop_cd][$mytitle] = $v["title_cd"];
					$datas[$shop_cd][$mypc]    = $v["pattern_cd"];
					$datas[$shop_cd][$mynpc]   = $v["pnums"];
					*/
				}
			}
		}
		


		//usset($details);
		
		$details = $dao_mg->getCellDetails( $pre_matrix_cd, TRUE, $aja_cd );
		//$data_title2     = $dao_mg->getTitle( $matrix_cd );
		
		foreach ( $details as $k => $v) {
			$bSize   = strtolower( $v["size"] );
			$shop_cd = $v["shop_cd"];
			$wtype   = $v["wtype"];//9  非例外曜日　0-6 例外曜日の番号
			$qtype   = $v["qtype"];//0  通常チラシ　1 地域１、2 地域2、3 地域3、4 地域4、5 地域5]
			if ( $qtype == "0" && isset($datas[$shop_cd]) ) {
				$mytitle = "ltitle_cd" ;
				$datas[$shop_cd][$mytitle] = $v["title"];
				if ( $wtype == "9" ) {
					
					$mymp = "lmp" ;
					$mymps = "lmps" ;
					$mypc    = "lpc_".$bSize;
					$mynpc   = "lnpc_".$bSize;
					
					$datas[$shop_cd][$mypc]    = $data_pattern_arr[ $v["pattern_cd"] ];
					$datas[$shop_cd][$mynpc]   = $v["pnums"];
					$datas[$shop_cd][$mymp]    = $v["map_no"];
					$datas[$shop_cd][$mymps]   = $v["isirgyu"];
					
				} else {
					$mytitle = "l".$data_cell_wsets[$wtype]["title_cd"] ;
					
					$mypc    = "l".$data_cell_wsets[$wtype]["pc_".$bSize];
					$mynpc   = "l".$data_cell_wsets[$wtype]["npc_".$bSize];
					$mysmpc  = "l".$data_cell_wsets[$wtype]["smpc_".$bSize];
					
					$datas[$shop_cd][$mytitle] = $v["title"];
					$datas[$shop_cd][$mypc]    = $data_pattern_arr[ $v["pattern_cd"] ];
					$datas[$shop_cd][$mynpc]   = $v["pnums"];
					$datas[$shop_cd][$mysmpc]  = $v["sample"];
				}
			}else {
				if ( $wtype == "9" ) {
					$mytitle = "l".$data_cell_losets[$qtype]["title_cd"] ;
					$mypc    = "l".$data_cell_losets[$qtype]["pc_".$bSize];
					$mynpc   = "l".$data_cell_losets[$qtype]["npc_".$bSize];
					
					$datas[$shop_cd][$mytitle] = $v["title"];
					$datas[$shop_cd][$mypc]    = $data_pattern_arr[ $v["pattern_cd"] ];
					$datas[$shop_cd][$mynpc]   = $v["pnums"];
					$datas[$shop_cd][$mysmpc]  = $v["sample"];
				} else {
					/*
					$dweeksets = $data_cell_losets[$qtype]["weeks"] ;
					
					$mytitle = $dweeksets[$wtype]["title_cd"] ;
					$mypc    = $dweeksets[$wtype]["pc_".$bSize];
					$mynpc   = $dweeksets[$wtype]["npc_".$bSize];
					
					$datas[$shop_cd][$mytitle] = $v["title_cd"];
					$datas[$shop_cd][$mypc]    = $v["pattern_cd"];
					$datas[$shop_cd][$mynpc]   = $v["pnums"];
					*/
				}
			}
		}
		
		$size_prices = $dao_mg->getQrsPrice($formdata["year4"],$aja_cd);
		$shop_rhizome =  $dao_mg->getShopRhizome($matrix_cd);
		$preshopweek = $dao_mg->getShopWeek($pre_matrix_cd);
		
		//店舗単価マスタ
		foreach ( $datas as $k => $v) {
			$datas[$k]["b2"] = empty($size_prices[$k]["b2"]) ? 0 : $size_prices[$k]["b2"];
			$datas[$k]["b3"] = empty($size_prices[$k]["b3"]) ? 0 : $size_prices[$k]["b3"];
			$datas[$k]["b4"] = empty($size_prices[$k]["b4"]) ? 0 : $size_prices[$k]["b4"];
			$datas[$k]["loc_cost"]   = empty($v["loc_cost"]) ? 0 : $v["loc_cost"];
			$datas[$k]["loc_cost"] = Class_PWD::cost_round ( $datas[$k]["loc_cost"]);
			
			if ( !empty($shop_rhizome[$k] )) {
				$datas[$k]["now_qua"]   = $shop_rhizome[$k]["now_quantity"];
				$datas[$k]["last_qua"]  = $shop_rhizome[$k]["last_quantity"];
			}else {
				$datas[$k]["now_qua"]   = 0 ;
				$datas[$k]["last_qua"]  = 0 ;
			}
			$datas[$k]["last_cost"] = empty($preshopweek[$k]) ? 0 : $preshopweek[$k]["cell_cost"] ;
			$datas[$k]["last_cost"] = Class_PWD::cost_round ($datas[$k]["last_cost"]);
		}
		//前年データを整形完了
		/*
		foreach ( $datas as $k => $v) {
			if ( isset($v["title_cd"]) ) {
				$maintitleID = $v["title_cd"];
				if  ( isset($data_title_map_arr[$maintitleID]) ) {
					$datas[$k]["irgyu"] = $data_title_map_arr[$maintitleID];
				}
			}
		}
		*/
	} 
	if ( $phase == 'input' ) {
		$data_pattern_nums = $dao_mg->getPatternNums( $aja_cd, $matrix_cd );
	}
}

if( isset( $errmsg ) )  $smarty->assign('errmsg',    $errmsg);

$smarty->assign('phase',  $phase );
$smarty->assign('menu',   $smarty->fetch('menu.html') );
$smarty->assign('logout', $smarty->fetch('logout.html') );
$smarty->assign('footer', $smarty->fetch('footer.html') );

if ($can_edit && $aja_exits) {
	if( isset( $formdata ) ) $smarty->assign('forms',  $formdata);
	$smarty->assign('edit_msg',   $edit_msg );
	$smarty->assign('title',      $data_title_arr );
	$smarty->assign('title_map',  $data_title_map_arr );
	
	$smarty->assign('shopmapno',  $shopmapno );
	$smarty->assign('title_week', $data_title_week_arr );
	$allpattern = array();
	foreach ( $datapattern as $k => $v) {
		$allpattern[$v["media_flg"]][$v["pattern_cd"]] = $v["pattern_name"] ; 
		//$allpattern[] $data_pattern_arr[$v["pattern_cd"]] = $v["pattern_name"];
	}
	
	$areapattern = Class_M_OTHER::get_pattern_array( NULL, 23);
	$smarty->assign('areapattern',      $areapattern );
	
	$smarty->assign('allpattern',      $allpattern );
	
	$smarty->assign('patternflags',    $aoki_pattern_flags );
	$smarty->assign('aokimapsort',     $aoki_map_sort );

	
	$smarty->assign('pattern',      $data_pattern_arr );
	$smarty->assign('pattern_nums', $data_pattern_nums );

	

	
//$fwidth = array("title" =>220, "size"=> 28,"sample" => 80, "num" => 80,"pattern" => 120   );
//$fwidth["cw"] = $fwidth["title"] + $fwidth["size"]+  $fwidth["sample"] +  $fwidth["num"]+  $fwidth["pattern"]+  $fwidth["sample"]+  $fwidth["num"]+  $fwidth["pattern"] + 12 ;
//$fwidth["ww"] = $fwidth["size"] +  $fwidth["sample"]  +  $fwidth["num"]+  $fwidth["pattern"] + 8;
//$fwidth["lw"] = $fwidth["cw"];
	
	$fwidth["colnums"] = 8; 
	$i   = 0;
	
	if ( count($data_cell_wsets) > 0 ) {
		foreach ($data_cell_wsets as $vv ){
			$fwidth["cw"] = $fwidth["cw"] + $fwidth["ww"] ;
			$fwidth["colnums"] = $fwidth["colnums"] + 3;
	 	}
		//$tor = $fwidth["cw"] + $fwidth["ww"] ;
	 }else {
	 	//echo "*************************";
	 }
	
	 $tol = 0;
	 $tor = $fwidth["cw"] + $fwidth["lw"]-2;
	 $fwidth["tabw"] = $fwidth["cw"] ;
	/*
	foreach ( $data_cell_wsets as $k=>$v) {
		$fwidth["colnums"] = $fwidth["colnums"] + 3;
		if ($i == 0){
			$data_cell_wsets[$k]["tol"] = $tol ;
			$data_cell_wsets[$k]["tor"] = $tor;
			$tol = $fwidth["cw"] ;
			$tor = $tor + $fwidth["ww"];
		}else {
			$data_cell_wsets[$k]["tol"] = $tol ;
			$data_cell_wsets[$k]["tor"] = $tor;
			$tol = $tol +  $fwidth["ww"]; 
			$tor = $tor +  $fwidth["ww"];
		}
		$fwidth["tabw"] = $fwidth["tabw"] + $fwidth["ww"] ;
		$i = $i + 1;
	}
	*/
	$smarty->assign('cell_wsets',   $data_cell_wsets );
	//if ( count($data_cell_wsets) > 0 ) {
	//	$tor = $tor + $fwidth["lw"]  - $fwidth["ww"] ;
	//}
	//$fwidth["cw"]  = $fwidth["cw"] -2;
	
	$i = 0;
	foreach ( $data_cell_losets as $k=>$v) {
		if ($i == 0){
			$data_cell_losets[$k]["tol"] = $tol ;
			$data_cell_losets[$k]["tor"] = $tor;
			$tol = $tor - $fwidth["lw"] ;
			$tor = $tor + $fwidth["lw"];
		}else {
			$data_cell_losets[$k]["tol"] = $tol ;
			$data_cell_losets[$k]["tor"] = $tor;
			$tol = $tol +  $fwidth["lw"]; 
			$tor = $tor + $fwidth["lw"];
		}
		$fwidth["tabw"] = $fwidth["tabw"] + $fwidth["lw"] ;
		$i = $i + 1;
	}
	$smarty->assign('cell_losets',  $data_cell_losets );
	
	$smarty->assign('data', $datas);
	$disp_td = array(1 => "経準高", 2 => "経費", 3 => "利益");
	$smarty->assign('disp_td', $disp_td);
	$smarty->assign('fw', $fwidth);
	
	
	$smarty->display('tmoncell_updatef.html');
	
} else {
	$forms["year4"]   =  $formdata["year4"] ;
	$forms["ww"]      =  $matrix_cd;
	$forms["sort"]    =  $_GET['sort'];
	$forms["areauser"]    =  $_GET['areauser'];
	$forms["zone_cd"]    =  $_GET['zone_cd'];
	
	require_once( '../system/cell_ajareks_sort.inc.php' );
	$smarty->assign('forms', $forms);
	
	$smarty->assign('year4',  Class_M_OTHER::get_years_array());
	$smarty->assign('errmsg',  $edit_msg);
	
	$week= Class_M_OTHER::get_week_array( $forms["year4"], PLEASE_SELECT_ARR ,FALSE, TRUE);
	$smarty->assign('week', $week );
	
	$smarty->display('tmoncell_update.html');
}

?>